package com.dcy.prototype.deepclone;

/**
 * @Author：dcy
 * @Description:
 * @Date: 2021/1/20 16:14
 */
public class Client {
    public static void main(String[] args) throws CloneNotSupportedException {
        DeepProtoType deepProtoType = new DeepProtoType();
        deepProtoType.name = "宋江";
        deepProtoType.deepCloneableTarget = new DeepCloneableTarget("大牛","大牛的类");

        //方式1 实现深拷贝
        DeepProtoType deepProtoType1 = (DeepProtoType)deepProtoType.clone();
        System.out.println("p.name" + deepProtoType.name+"p.deepCloneableTarget" + deepProtoType.deepCloneableTarget.hashCode());
        System.out.println("p1.name" + deepProtoType1.name+"p1.deepCloneableTarget" + deepProtoType1.deepCloneableTarget.hashCode());

        System.out.println("==========================");
        //方式 2完成深拷贝
        DeepProtoType p2 = (DeepProtoType) deepProtoType.deepClone();
        System.out.println("p.name=" + deepProtoType.name + "p.deepCloneableTarget=" + deepProtoType.deepCloneableTarget.hashCode());
        System.out.println("p2.name=" + p2.name + "p2.deepCloneableTarget=" + p2.deepCloneableTarget.hashCode());

    }
}
